#ifndef PIPE_STREAM_H
#define PIPE_STREAM_H



#include "drm_drv/drm_plane_drv.h"
#include "v4l2_drv/v4l2_capture.h"
#include <unistd.h>

#define MAX_PLANE_COUNT 10

enum Pipe_Convert_Type{
    nv12_nv12,
    nv12_rgb,
    yuyv_rgb,
    rgb_rgb,
    rgb_nv12,
    merge,
};
enum Pipe_Stream_State{
    ps_init,
    ps_runing,
    ps_stoping,
    ps_stoped
};
class Pipe_Stream {
private:
    struct drm_plane *plane=NULL;
    Capture *cap=NULL;
    Pipe_Stream_State status=ps_init;
    std::mutex status_mutex;
    std::thread *pipeThread;

    void re_run(){
        status_mutex.lock();
        status=ps_runing;
        status_mutex.unlock();
    }
    void stream_process_nv12_nv12();
    void stream_process_nv12_rgb();
    void stream_process_yuyv_rgb();
    void stream_process_rgb_rgb();
    void stream_process_rgb_nv12();

public:
//    int cap_id=0;
//    int plane_id=0;

    Pipe_Convert_Type convert_type=nv12_nv12;
    Pipe_Stream(){

    }
    void set_status(Pipe_Stream_State tmp){
        status_mutex.lock();
        status=tmp;
        status_mutex.unlock();
    }
    Pipe_Stream_State get_status(void){
        Pipe_Stream_State tmp;
        status_mutex.lock();
        tmp=status;
        status_mutex.unlock();
        return tmp;
    }
    void stoping(){
        status_mutex.lock();
        status=ps_stoping;
        status_mutex.unlock();
    }
    void wait_stoping(void){
        while(get_status()!=ps_stoped){
            usleep(100);
        }
    }
    void stop(){
        if(get_status()==ps_runing){
            stoping();
            wait_stoping();
        }
    }

    void start(Capture *cap,struct drm_plane *plane,Pipe_Convert_Type type =nv12_nv12);


};

void pipe_stop_all(Pipe_Stream *pipe);


#endif // DRM_PIPE_H
